/**
 * 功能描述�?
 */

define(function (require, exports, module) {
	var Dialog = require("dialog");
	var Tools = require("tools");
	
    module.exports = {
    		countPerNumber : function(widget){
    			var editGridData = widget.get("editgrid").getData();
    			
    			if(editGridData.length){
    				var signUpNumber = editGridData.length;
    				widget.get("form").setValue("signUpNumber", signUpNumber);
    			}
    		},
    		
    		checkData : function(params, widget){
    			
    			var idNumber = params["personalInfo.idNumber"];
                var name = params["personalInfo.name"];
                var sex = params["personalInfo.sex"];
                var mobilePhone = params["personalInfo.mobilePhone"];
    			
    			if(idNumber.getValue() == ""){
                	Dialog.alert({
                		tip : "提示",
                		content : "身份证号不能为空"
                	})
                	return false;
                }
    			if(!Tools.isIdentityCodeValid(idNumber.getValue())){
                	Dialog.alert({
                		tip : "提示",
                		content : "请输入合法的身份证号码"
                	})
                	return false;
                }
    			
    			var editData = widget.get("editgrid").getData();
    			var flag = true;
    			for(var i = 0; i < editData.length; i++){
    				if(idNumber.getValue() == editData[i].personalInfo.idNumber){
    					flag = false;
    				}
    			}
    			if(!flag){
    				Dialog.alert({
                		tip : "提示",
                		content : "存在重复的身份证号码"
                	})
                	return false;
    			}
    			
    			if(name.getValue() == ""){
                	Dialog.alert({
                		tip : "提示",
                		content : "请输入姓名"
                	})
                	return false;
                }
                if(sex.getData(sex.getValue()).length == 2){
                	Dialog.alert({
                		tip : "提示",
                		content : "请选择性别"
                	})
                	return false;
                }
                var reg = "-?(0|[1-9]\d*)(\.\d+)?";
				var re = new RegExp(reg);
                if(mobilePhone.getValue() == ""){
                	Dialog.alert({
                		tip : "提示",
                		content : "请输入手机号"
                	})
                	return false;
                }
                if(mobilePhone.getValue().search(re) == -1){
                	Dialog.alert({
                		tip : "提示",
                		content : "请输入合法的手机号码"
                	})
                	return false;
                }
                
                return true;
    		}
    		
    };
});
